import { wxRequest } from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imgUrl,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    hideDetail: true,
    detail: {},
    list:[],
    pageNo:1,
    hasNextPage:false,
    sharedType:''
  },

  onLoad: function (options) {
    console.log(options.id,'id')
    if (options.id) {
      this.setData({
        id: options.id,
        sharedType: options.sharedType
      })
    }
  },

  onShow: function () {
    this.getdetail()
  },

  //显示隐藏
  detailState: function () {
    this.setData({
      hideDetail: !this.data.hideDetail
    })
  },

  //复制订单号
  copy: function (e) {
    var that = this;
    var text = e.currentTarget.dataset.text
    wx.setClipboardData({
      //去找上面的数据
      data: text,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
        });
      }
    });
  },


  //获取详情
  getdetail: function () {
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/odr/protected/settle/detail?setId=' + this.data.id + '&pageNo=' + this.data.pageNo,
      method: 'POST',
    }, (res) => {
      var resVo = res.vo
      var list=res.list

      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }


      console.log(resVo, 'resVo')
      this.setData({
        detail: resVo,
        list,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      })
    })
  },

  //下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function () {
    this.setData({
      pageNo: 1
    })
    this.getdetail();
  },

  //触底时，加载更多
  onReachBottom: function () {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getdetail();
    }
  },

  //去发货
  toDelives: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/menber/mall/deliver?id=' + id
    }) 
  },

  toDtail: function (e) {
    var id = e.currentTarget.dataset.id;
    console.log(id, 'id')
    wx.navigateTo({
      url: '/pages/menber/mall/detail?id=' + e.currentTarget.dataset.id + "&typefg=1",
    })
  }

})